package org.irri.smta.domain;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;


@MappedSuperclass
public abstract class IdEntity extends EntityBase {

	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "ID", unique = true, nullable = true)
	private Long id;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Long otherId = null;
		if (obj instanceof IdEntity) {
			IdEntity other = (IdEntity) obj;
			otherId = other.getId();
		} else {
			return false;
		}
		if (getId() == null) {
			if (otherId != null) {
				return false;
			}
		} else if (getId().longValue() != otherId.longValue()) {
			return false;
		}
		return true;
	}

	public String toString() {
		if (id != null) {
			return id.toString();
		}
		return null;
	}

}
